home *** CD-ROM | disk | FTP | other *** search
-
- /*© Copyright 1988-1992 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include <GestaltEqu.h>
- #include <iac.h>
- #include <menusharing.h>
- #include "appletinternal.h"
- #include "appletmain.h"
- #include "appletmenu.h"
- #include "appletscrollbar.h"
- #include "appletabout.h"
- #include "appletmenuops.h"
- #include "appletresource.h"
-
-
- /*
- IAC messages implemented by the Applet Toolkit layer.
- */
- #define alertdialogtoken 'alrt'
- #define confirmdialogtoken 'cnfm'
- #define askdialogtoken 'askd'
-
- #define enabledialogtoken 'enbd'
- #define geterrorstringtoken 'gers'
-
- #define gettargettoken 'gtrg'
- #define settargettoken 'strg'
-
- #define newwindowtoken 'nwin'
- #define openwindowtoken 'owin'
- #define closewindowtoken 'cwin'
- #define savewindowtoken 'swin'
- #define revertwindowtoken 'rwin'
- #define movewindowtoken 'mwin'
- #define printwindowtoken 'pwin'
- #define selectwindowtoken 'xwin'
- #define zoomwindowtoken 'zwin'
-
- #define getfilepathtoken 'gpth'
- #define getwindowpostoken 'gwps'
- #define madechangestoken 'chgs'
-
- #define getpicttoken 'gpic'
- #define gettexttoken 'gtex'
- #define putpicttoken 'ppic'
- #define puttexttoken 'ptex'
- #define selectalltoken 'sela'
- #define haveselectiontoken 'hsel'
-
- #define countwindowstoken 'twin'
- #define nthwindowtoken 'nthw'
- #define quittoken 'quit'
-
- #define setfonttoken 'sfon'
- #define setfontsizetoken 'sfsz'
-
- /*
- new undocumented verbs
- */
- #define getpagerecttoken 'gprc'
- #define getwindowrecttoken 'gwrc'
- #define getbinarytoken 'gbin'
- #define putbinarytoken 'pbin'
- #define scrollwindowtoken 'lwin'
- #define perftesttoken 'perf'
-
-
-
- /*
- for communication with the applet body code -- it has copies of all the globals,
- and pointers to the callback routines that define the applet.
- */
- tyappletrecord app;
-
- /*
- globals used by the window visiter.
- */
- bigstring bsvisit;
- short vnumvisit;
- short x1, x2; /*two short registers for visit routines*/
- hdlappwindow lastwindowvisited;
-
-
- /*
- flag to control whether the user is interacting, or we're responding to an
- interapplication message. the error string is saved -- to be accessed by the
- GetErrorString verb.
- */
- boolean fldialogsenabled = true;
- bigstring bserrorstring;
-
-
- /*
- set true if the last event was a keystroke and it was cmd-period.
- */
- boolean flcmdperiod = false;
-
-
- /*
- for fast events, we need to store a pointer to our application heap, so any
- allocations we do happen in the right heap.
- */
- static THz appletheapzone;
-
-
- typedef struct tydiskwindowinfo { /*saved on disk after the applet's data handle*/
-
- short versionnumber;
-
- Rect windowrect;
-
- short vertmin, vertmax, vertcurrent;
-
- short horizmin, horizmax, horizcurrent;
-
- diskfontstring defaultfontstring;
-
- short defaultsize;
-
- tyjustification defaultjustification;
-
- char waste [64]; /*room to grow*/
- } tydiskwindowinfo;
-
- EventRecord appletevent; /*the last event received by appletmain.c*/
-
- boolean flexitmainloop = false;
-
- #define nowindowerror 7 /*index into the verb error STR# list*/
- #define windowopenerror 8
- #define nopictcallbackerror 9
- #define notextcallbackerror 10
- #define noputtextcallbackerror 11
- #define noputpictcallbackerror 12
-
-
- bigstring bstargetwindowname; /*title of window that IAC verbs apply to*/
-
- static boolean flcurrentlyactive = true; /*we start active, then get juggled*/
-
-
- #define jugglerEvt 15 /*a suspend/resume event from the OS to us*/
-
- typedef struct tyjugglermessage {
-
- long eventtype: 8; /*bits 24 -- 31*/
-
- long reservedbits: 22; /*bits 2 -- 23*/
-
- long flconvertclipboard: 1; /*bit 1*/
-
- long flresume: 1; /*bit 0*/
- } tyjugglermessage;
-
-
- #define displaydebug true
-
- #define minwindowwidth 125
- #define minwindowheight 100
-
-
-
- static void debugrect (Rect r) {
-
- if (displaydebug) {
-
- FillRect (&r, gray);
-
- FrameRect (&r);
- }
- } /*debugrect*/
-
-
- static void zzz (void) {
-
- bigstring bs;
- Rect r = (**(**app.appwindow).hpalette).r;
-
- setstringlength (bs, 0);
-
- pushint (r.top, bs); pushstring ("\p, ", bs);
-
- pushint (r.left, bs); pushstring ("\p, ", bs);
-
- pushint (r.bottom, bs); pushstring ("\p, ", bs);
-
- pushint (r.right, bs);
-
- DebugStr (bs);
- } /*zzz*/
-
-
- void apperaserect (Rect r) {
-
- pushclip (r);
-
- (*app.eraserectcallback) (r);
-
- popclip ();
- } /*apperaserect*/
-
-
- boolean appalert (bs) bigstring bs; {
-
- copystring (bs, bserrorstring);
-
- if (!fldialogsenabled)
- return (true);
-
- return (alertdialog (bs));
- } /*appalert*/
-
-
- boolean appconfirm (bs) bigstring bs; {
-
- copystring (bs, bserrorstring);
-
- if (!fldialogsenabled)
- return (true);
-
- return (confirmdialog (bs));
- } /*appconfirm*/
-
-
- boolean appask (bigstring prompt, bigstring answer) {
-
- copystring (prompt, bserrorstring);
-
- if (!fldialogsenabled)
- return (true);
-
- return (askdialog (prompt, answer));
- } /*appask*/
-
-
- void setselectionstyleinfo (tyselectioninfo *pselinfo, boolean flpack) {
-
- union {
-
- short fontstyle;
-
- struct {
-
- int extrabits: 7; /*highest-order 7 bits are unused*/
-
- boolean flsubscript: 1;
-
- boolean flsuperscript: 1;
-
- boolean flextended: 1; /*not currently used*/
-
- boolean flcondensed: 1;
-
- boolean flshadow: 1;
-
- boolean floutline: 1;
-
- boolean flunderline: 1;
-
- boolean flitalic: 1;
-
- boolean flbold: 1;
- } stylebits;
- } u;
-
- tyselectioninfo x = *pselinfo;
-
- if (flpack) {
-
- u.fontstyle = 0; /*clear all bits*/
-
- u.stylebits.flsubscript = x.flsubscript;
-
- u.stylebits.flsuperscript = x.flsuperscript;
-
- u.stylebits.flextended = x.flextended;
-
- u.stylebits.flcondensed = x.flcondensed;
-
- u.stylebits.flshadow = x.flshadow;
-
- u.stylebits.floutline = x.floutline;
-
- u.stylebits.flunderline = x.flunderline;
-
- u.stylebits.flitalic = x.flitalic;
-
- u.stylebits.flbold = x.flbold;
-
- x.fontstyle = u.fontstyle;
- }
- else {
- u.fontstyle = x.fontstyle;
-
- x.flsubscript = bitboolean (u.stylebits.flsubscript);
-
- x.flsuperscript = bitboolean (u.stylebits.flsuperscript);
-
- x.flextended = bitboolean (u.stylebits.flextended);
-
- x.flcondensed = bitboolean (u.stylebits.flcondensed);
-
- x.flshadow = bitboolean (u.stylebits.flshadow);
-
- x.floutline = bitboolean (u.stylebits.floutline);
-
- x.flunderline = bitboolean (u.stylebits.flunderline);
-
- x.flitalic = bitboolean (u.stylebits.flitalic);
-
- x.flbold = bitboolean (u.stylebits.flbold);
- }
-
- *pselinfo = x;
- } /*setselectionstyleinfo*/
-
-
- void drawappgrowicon (appwindow) hdlappwindow appwindow; {
-
- register WindowPtr w = (**appwindow).macwindow;
-
- if ((**appwindow).flprinting)
- return;
-
- if (app.vertscroll && app.horizscroll) {
-
- DrawGrowIcon (w);
- }
- else {
- register short width = 15;
- Rect rport = (*w).portRect;
- Rect rclip;
-
- rclip = rport;
-
- rclip.left = rclip.right - width;
-
- rclip.top = rclip.bottom - width;
-
- pushclip (rclip);
-
- DrawGrowIcon (w);
-
- popclip ();
- }
- } /*drawappgrowicon*/
-
-
- boolean apppushwindow (appwindow) hdlappwindow appwindow; {
-
- return (pushmacport ((**appwindow).macwindow));
- } /*apppushwindow*/
-
-
- boolean apppopwindow (void) {
-
- return (popmacport ());
- } /*apppopwindow*/
-
-
- boolean apppushorigin (void) {
-
- hdlappwindow ha = app.appwindow;
-
- if (ha != nil) {
-
- (**ha).originpushdepth++;
-
- if ((**ha).originpushdepth == 1) {
-
- SetOrigin ((**ha).scrollorigin.h, (**ha).scrollorigin.v);
-
- OffsetRgn ((*(**ha).macwindow).clipRgn, (**ha).scrollorigin.h, (**ha).scrollorigin.v);
- }
- }
- } /*apppushorigin*/
-
-
- boolean apppoporigin (void) {
-
- hdlappwindow ha = app.appwindow;
-
- if (ha != nil) {
-
- (**ha).originpushdepth--;
-
- if ((**ha).originpushdepth == 0) {
-
- OffsetRgn ((*(**ha).macwindow).clipRgn, -(**ha).scrollorigin.h, -(**ha).scrollorigin.v);
-
- SetOrigin (0, 0);
- }
- }
- } /*apppoporigin*/
-
-
- boolean apppushclip (Rect r) {
-
- /*
- this front-end for pushclip respects the current settings of the origin. applets
- should call this routine instead of calling the quickdraw.c routine.
- */
-
- hdlappwindow ha = app.appwindow;
-
- pushclip (r);
-
- if ((**ha).originpushdepth > 0)
- OffsetRgn ((*(**ha).macwindow).clipRgn, -(**ha).scrollorigin.h, -(**ha).scrollorigin.v);
- } /*apppushclip*/
-
-
- boolean apppopclip (void) {
-
- /*
- this front-end for popclip respects the current settings of the origin. applets
- should call this routine instead of calling the quickdraw.c routine.
- */
-
- hdlappwindow ha = app.appwindow;
-
- popclip ();
-
- if ((**ha).originpushdepth > 0)
- OffsetRgn ((*(**ha).macwindow).clipRgn, -(**ha).scrollorigin.h, -(**ha).scrollorigin.v);
- } /*apppopclip*/
-
-
- void appprecallback (void) {
-
- hdlappwindow ha = app.appwindow;
-
- if (ha != nil) {
-
- pushclip ((**ha).contentrect);
-
- apppushorigin ();
- }
-
- (*app.setglobalscallback) (); /*app can copy from app.appdata, appwindow to its own globals*/
- } /*appprecallback*/
-
-
- void apppostcallback (void) {
-
- hdlappwindow ha = app.appwindow;
-
- if (ha != nil) {
-
- apppoporigin ();
-
- popclip ();
- }
- } /*apppostcallback*/
-
-
- boolean appopenbitmap (r, appwindow) Rect r; hdlappwindow appwindow; {
-
- return (openbitmap (r, (**appwindow).macwindow));
- } /*appopenbitmap*/
-
-
- boolean appclosebitmap (appwindow) hdlappwindow appwindow; {
-
- closebitmap ((**appwindow).macwindow);
-
- return (true);
- } /*appclosebitmap*/
-
-
- void getappdata (w, appdata) WindowPtr w; Handle *appdata; {
-
- /*
- a window's refcon field points to the appwindow record, which in turn
- points to the applet's data in the appdata field.
- */
-
- register hdlappwindow ha = (hdlappwindow) (*(WindowPeek) w).refCon;
-
- if (ha == nil)
- *appdata = nil;
- else
- *appdata = (**ha).appdata;
- } /*getappdata*/
-
-
- static boolean getwindowrefcon (w, refcon) WindowPtr w; long *refcon; {
-
- /*
- 9/30/92 dmb: carefully ensure that the window is one that is being managed
- by the Applet Toolkit -- use a heuristic that makes sense -- see below.
-
- return false if a valid refon isn't extracted.
- */
-
- register long x;
-
- *refcon = 0; /*default*/
-
- x = (*(WindowPeek) w).refCon;
-
- if (x == 0)
- return (false);
-
- if (odd (x))
- return (false);
-
- if (gethandlesize ((Handle) x) < sizeof (tyappwindow))
- return (false);
-
- if ((**(hdlappwindow) x).macwindow != w) /*sensible heuristic to skip other people's windows*/
- return (false);
-
- *refcon = x;
-
- return (true);
- } /*getwindowrefcon*/
-
-
- void getappwindowtitle (appwindow, bs) hdlappwindow appwindow; bigstring bs; {
-
- if (appwindow == nil)
- setstringlength (bs, 0);
- else
- GetWTitle ((**appwindow).macwindow, bs);
- } /*selectappwindow*/
-
-
- void setappwindowtitle (appwindow, bs) hdlappwindow appwindow; bigstring bs; {
-
- SetWTitle ((**appwindow).macwindow, bs);
- } /*setappwindowtitle*/
-
-
- void showappwindow (appwindow) hdlappwindow appwindow; {
-
- ShowWindow ((**appwindow).macwindow);
- } /*showappwindow*/
-
-
- void selectappwindow (appwindow) hdlappwindow appwindow; {
-
- SelectWindow ((**appwindow).macwindow);
- } /*selectappwindow*/
-
-
- void invalappwindow (appwindow, flerase) hdlappwindow appwindow; boolean flerase; {
-
- Rect r;
-
- pushmacport ((**appwindow).macwindow);
-
- r = (**appwindow).windowrect;
-
- invalrect (r);
-
- if (flerase)
- apperaserect (r);
-
- popmacport ();
- } /*invalappwindow*/
-
-
- void setappwindow (appwindow) hdlappwindow appwindow; {
-
- register hdlappwindow ha = appwindow;
-
- app.appwindow = ha;
-
- if (ha == nil) {
-
- app.appdata = nil;
- }
- else {
- app.appdata = (**ha).appdata;
-
- (*app.setglobalscallback) (); /*app can copy from app.appdata to its own globals*/
-
- SetPort ((**ha).macwindow);
-
- ClipRect (&(**ha).contentrect);
- }
- } /*setappwindow*/
-
-
- boolean apprectneedsupdate (Rect r) {
-
- register WindowPtr w = (**app.appwindow).macwindow;
-
- return (RectInRgn (&r, (*w).visRgn));
- } /*apprectneedsupdate*/
-
-
- void appinvalstatusseparator (void) {
-
- Rect r = (**app.appwindow).statusrect;
-
- r.top = r.bottom;
-
- r.bottom += 2;
-
- InvalRect (&r);
- } /*appinvalstatusseparator*/
-
-
- void updateappwindow (appwindow) hdlappwindow appwindow; {
-
- /*
- DW 4/24/92: reordered things for IOWA.
-
- DW 4/25/92: added updating of palette.
-
- DW 4/30/92: added pre-update callback to allow IOWA to inval all dirty objects.
- */
-
- register hdlappwindow ha = appwindow;
- register WindowPtr w = (**ha).macwindow;
- Rect rwindow = (*w).portRect;
- Rect rstatus = (**ha).statusrect;
-
- appprecallback ();
-
- (*app.preupdatecallback) ();
-
- apppostcallback ();
-
- BeginUpdate (w);
-
- setappwindow (ha);
-
- /*update the palette*/ {
-
- if (app.haspalette) {
-
- if (apprectneedsupdate ((**(**ha).hpalette).r)) {
-
- pushclip (rwindow);
-
- paletteupdate ((**ha).hpalette);
-
- popclip ();
- }
- }
- }
-
- /*update the status area*/ {
-
- if (app.statuspixels > 0) { /*has a status area*/
-
- Rect r = rstatus;
-
- r.top = r.bottom;
-
- r.bottom += 4;
-
- if (apprectneedsupdate (r)) { /*draw the double separator line*/
-
- r.bottom -= 2;
-
- pushclip (rwindow);
-
- debugrect (r);
-
- apperaserect (r);
-
- MoveTo (r.left, r.top);
-
- LineTo (r.right, r.top);
-
- MoveTo (r.left, r.bottom);
-
- LineTo (r.right, r.bottom);
-
- popclip ();
- }
-
- if (apprectneedsupdate (rstatus)) {
-
- pushclip (rstatus);
-
- (*app.updatestatuscallback) ();
-
- popclip ();
- }
- }
- }
-
- /*let the applet update his stuff*/ {
-
- Rect rcontent = (**ha).contentrect;
-
- if (apprectneedsupdate (rcontent)) {
-
- appprecallback ();
-
- (**ha).updaterect = (**(*w).visRgn).rgnBBox;
-
- (*app.setglobalscallback) (); /*app can copy from app.appdata to its own globals*/
-
- (*app.updatecallback) ();
-
- apppostcallback ();
- }
- }
-
- /*update the grow icon, scrollbars*/ {
-
- pushclip (rwindow);
-
- drawappgrowicon (ha);
-
- updateappscrollbars (ha);
-
- popclip ();
- }
-
- EndUpdate (w);
- } /*updateappwindow*/
-
-
- void computewindowinfo (macwindow, appwindow) WindowPtr macwindow; hdlappwindow appwindow; {
-
- register WindowPtr w = macwindow;
- register hdlappwindow ha = appwindow;
- hdlpaletterecord hpal = (hdlpaletterecord) (**appwindow).hpalette;
- Rect r, rcontent, rstatus, rpalette;
-
- (**ha).windowrect = r = (*w).portRect;
-
- rcontent = r;
-
- /*take out for scrollbars*/ {
-
- register short scrollbarwidth = getscrollbarwidth ();
-
- if (app.vertscroll)
- rcontent.right -= scrollbarwidth - 1;
-
- if (app.horizscroll)
- rcontent.bottom -= scrollbarwidth - 1;
- }
-
- if (app.statuspixels > 0) /*has a status area*/
- rcontent.top += app.statuspixels + 3; /*a 3-pixel line separates status & content*/
-
- if (app.haspalette) { /*has an icon palette*/
-
- rpalette = rcontent;
-
- rcontent.left += (**hpal).palettewidth;
-
- rpalette.right = rcontent.left;
- }
- else
- zerorect (&rpalette);
-
- (**ha).oldcontentrect = (**ha).contentrect;
-
- (**ha).contentrect = rcontent;
-
- if (app.haspalette)
- (**(**ha).hpalette).r = rpalette;
-
- rstatus = r; /*copy left, right, top*/
-
- rstatus.bottom = rstatus.top + app.statuspixels;
-
- (**ha).statusrect = rstatus;
-
- (**ha).windowvertpixels = r.bottom - r.top;
-
- (**ha).windowhorizpixels = r.right - r.left;
-
- (**ha).defaultfont = app.defaultfont;
-
- (**ha).defaultsize = app.defaultsize;
-
- (**ha).defaultstyle = app.defaultstyle;
-
- (**ha).defaultjustification = leftjustified;
-
- pushmacport (w);
-
- pushstyle ((**ha).defaultfont, (**ha).defaultsize, (**ha).defaultstyle);
-
- (**ha).fontheight = globalfontinfo.ascent + globalfontinfo.descent;
-
- popstyle ();
-
- popmacport ();
-
- (**ha).macwindow = w;
- } /*computewindowinfo*/
-
-
- void getdesktoprect (hdlappwindow appwindow, Rect *rwindow) {
-
- register WindowPtr w = (**appwindow).macwindow;
-
- *rwindow = (*w).portRect;
-
- pushmacport (w);
-
- localtoglobalrect (rwindow);
-
- popmacport ();
- } /*getdesktoprect*/
-
-
- void disposeappwindow (appwindow) hdlappwindow appwindow; {
-
- register hdlappwindow ha = app.appwindow;
-
- (*app.disposerecordcallback) ();
-
- if (app.haspalette)
- disposepalette ((hdlpaletterecord) (**ha).hpalette);
-
- disposescrollbar ((**ha).vertbar);
-
- disposescrollbar ((**ha).horizbar);
-
- DisposeWindow ((**ha).macwindow);
-
- disposehandle ((Handle) ha);
-
- setfrontglobals ();
- } /*disposeappwindow*/
-
-
- typedef boolean (*tyvisitapproutine) (hdlappwindow);
-
-
- boolean visitappwindows (visitproc) tyvisitapproutine visitproc; {
-
- /*
- visit all the windows from front to back. call the visitproc for each window,
- if it returns false we stop the traversal and return false.
-
- the visitproc takes one parameter -- a window pointer, indicating the window
- to be visited.
-
- return true if all the visits returned true.
-
- 9/4/91 DW: add lastwindowvisited -- returns nil if no match found, returns
- pointing to the appwindow record for the window that matched the visitproc's
- criteria.
-
- 5/24/92 DW: skip windows that obviously aren't being managed by the Applet
- Toolkit -- use a heuristic that makes sense -- see getwindowrefcon.
- */
-
- register WindowPtr w = FrontWindow ();
- hdlappwindow appwindow;
-
- lastwindowvisited = nil;
-
- while (w != nil) {
-
- if (!getwindowrefcon (w, (long *) &appwindow))
- goto next;
-
- if (!(*visitproc) (appwindow)) { /*stop the traversal*/
-
- lastwindowvisited = appwindow; /*set global*/
-
- return (false);
- }
-
- next:
-
- w = (WindowPtr) (*(WindowPeek) w).nextWindow;
- } /*while*/
-
- return (true); /*completed the traversal*/
- } /*visitappwindows*/
-
-
- boolean selectvisit (appwindow) hdlappwindow appwindow; {
-
- bigstring bs;
-
- getappwindowtitle (appwindow, bs);
-
- if (!equalstrings (bsvisit, bs)) /*no match -- keep traversing*/
- return (true);
-
- /*found a match, select the window, stop the traversal*/
-
- selectappwindow (appwindow);
-
- return (false); /*stop the traversal*/
- } /*selectvisit*/
-
-
- boolean selectwindowbytitle (bs) bigstring bs; {
-
- /*
- visit all the windows from front to back. when we encounter one of the
- app's windows check the window title. if it equals bs, then select the
- window and set the globals accordingly.
-
- return false if there is no app window with that name.
- */
-
- copystring (bs, bsvisit); /*copy into global so visit routine can access*/
-
- return (!visitappwindows (&selectvisit));
- } /*selectwindowbytitle*/
-
-
- boolean findbytitlevisit (appwindow) hdlappwindow appwindow; {
-
- bigstring bs;
-
- getappwindowtitle (appwindow, bs);
-
- if (!equalstrings (bsvisit, bs)) /*no match -- keep traversing*/
- return (true);
-
- return (false); /*stop the traversal*/
- } /*findbytitlevisit*/
-
-
- boolean findbywindowtitle (bstitle, appwindow) bigstring bstitle; hdlappwindow *appwindow; {
-
- copystring (bstitle, bsvisit); /*copy into global so visit routine can access*/
-
- visitappwindows (&findbytitlevisit);
-
- if (lastwindowvisited == nil)
- return (false);
-
- *appwindow = lastwindowvisited;
-
- return (true);
- } /*findbywindowtitle*/
-
-
- boolean findnthvisit (appwindow) hdlappwindow appwindow; {
-
- return (++x2 < x1); /*visit until they're equal*/
- } /*findnthvisit*/
-
-
- boolean findnthwindow (n, appwindow) short n; hdlappwindow *appwindow; {
-
- x1 = n; /*copy into a "register" for visit routine*/
-
- x2 = 0; /*another register*/
-
- visitappwindows (&findnthvisit);
-
- *appwindow = lastwindowvisited;
-
- return (lastwindowvisited != nil);
- } /*findbywindowtitle*/
-
-
- boolean countwindowsvisit (appwindow) hdlappwindow appwindow; {
-
- x1++;
-
- return (true); /*keep going*/
- } /*countwindowsvisit*/
-
-
- short countwindows (void) {
-
- x1 = 0; /*copy into a "register" for visit routine*/
-
- visitappwindows (&countwindowsvisit);
-
- return (x1);
- } /*countwindows*/
-
-
- boolean resetdirtyscrollbarsvisit (appwindow) hdlappwindow appwindow; {
-
- register hdlappwindow ha = appwindow;
-
- setappwindow (ha);
-
- if ((**ha).flresetscrollbars) {
-
- resetappscrollbars (ha);
-
- (**ha).flresetscrollbars = false; /*consume it*/
- }
-
- return (true); /*visit all open windows*/
- } /*resetdirtyscrollbarsvisit*/
-
-
- boolean resetdirtyscrollbars (void) {
-
- visitappwindows (&resetdirtyscrollbarsvisit);
- } /*resetdirtyscrollbars*/
-
-
- boolean getuntitledtitle (bs) bigstring bs; {
-
- register long ct = 1;
- hdlappwindow appwindow;
-
- while (true) {
-
- copystring ("\pUntitled ", bs);
-
- pushlong (ct++, bs);
-
- if (!findbywindowtitle (bs, &appwindow))
- return (true);
- } /*while*/
- } /*getuntitledtitle*/
-
-
- boolean findbyfilevisit (appwindow) hdlappwindow appwindow; {
-
- if ((**appwindow).vnum = vnumvisit) {
-
- if (equalstrings ((**appwindow).fname, bsvisit))
- return (false);
- }
-
- return (true); /*keep visiting*/
- } /*findbyfilevisit*/
-
-
- boolean findbyfile (bigstring fname, short vnum, hdlappwindow *appwindow) {
-
- copystring (fname, bsvisit); /*copy into global so visit routine can access*/
-
- vnumvisit = vnum; /*copy into global*/
-
- visitappwindows (&findbyfilevisit);
-
- if (lastwindowvisited == nil)
- return (false);
-
- *appwindow = lastwindowvisited;
-
- return (true);
- } /*findbyfile*/
-
-
- boolean settargetvisit (appwindow) hdlappwindow appwindow; {
-
- bigstring bs;
-
- getappwindowtitle (appwindow, bs);
-
- if (!equalstrings (bsvisit, bs)) /*no match -- keep traversing*/
- return (true);
-
- /*found a match, stop the traversal*/
-
- setappwindow (appwindow);
-
- return (false); /*stop the traversal*/
- } /*settargetvisit*/
-
-
- boolean setapptarget (bs) bigstring bs; {
-
- /*
- set the globals for the window with the indicated name without bringing
- the window to the front.
- */
-
- setappwindow (nil);
-
- copystring (bs, bsvisit); /*copy into global so visit routine can access*/
-
- visitappwindows (&settargetvisit);
-
- return (app.appwindow != nil);
- } /*setapptarget*/
-
-
- boolean setfrontglobalsvisit (appwindow) hdlappwindow appwindow; {
-
- setappwindow (appwindow);
-
- return (false); /*stop the traversal*/
- } /*setfrontglobalsvisit*/
-
-
- boolean setfrontglobals (void) {
-
- setappwindow (nil);
-
- visitappwindows (&setfrontglobalsvisit);
-
- return (app.appwindow != nil);
- } /*setfrontglobals*/
-
-
- void moveappwindow (hdlappwindow appwindow, Rect r) {
-
- register WindowPtr w = (**appwindow).macwindow;
-
- constraintodesktop (&r);
-
- SizeWindow (w, r.right - r.left, r.bottom - r.top, true);
-
- MoveWindow (w, r.left, r.top, false);
-
- computewindowinfo (w, appwindow);
-
- resizeappscrollbars (appwindow);
-
- resetappscrollbars (appwindow);
- } /*moveappwindow*/
-
-
- static void saveappwindowinfo (hdlappwindow appwindow, tydiskwindowinfo *appwindowinfo) {
-
- register hdlappwindow ha = appwindow;
- tydiskwindowinfo x;
- Rect r;
-
- clearbytes (&x, longsizeof (x));
-
- x.versionnumber = 1;
-
- getdesktoprect (ha, &x.windowrect);
-
- getscrollbarinfo ((**ha).vertbar, &x.vertmin, &x.vertmax, &x.vertcurrent);
-
- getscrollbarinfo ((**ha).horizbar, &x.horizmin, &x.horizmax, &x.horizcurrent);
-
- x.defaultsize = (**ha).defaultsize;
-
- x.defaultjustification = (**ha).defaultjustification;
-
- diskgetfontname ((**ha).defaultfont, x.defaultfontstring);
-
- *appwindowinfo = x;
- } /*saveappwindowinfo*/
-
-
- static void loadappwindowinfo (hdlappwindow appwindow, tydiskwindowinfo appwindowinfo) {
-
- register hdlappwindow ha = appwindow;
- tydiskwindowinfo x = appwindowinfo;
- short fontnum;
-
- moveappwindow (ha, x.windowrect);
-
- setscrollbarinfo ((**ha).vertbar, x.vertmin, x.vertmax, x.vertcurrent);
-
- setscrollbarinfo ((**ha).horizbar, x.horizmin, x.horizmax, x.horizcurrent);
-
- /*
- (**ha).scrollorigin.v = x.vertcurrent;
-
- (**ha).scrollorigin.h = x.horizcurrent;
- */
-
- (**ha).defaultsize = x.defaultsize;
-
- (**ha).defaultjustification = x.defaultjustification;
-
- diskgetfontnum (x.defaultfontstring, &fontnum);
-
- (**ha).defaultfont = fontnum;
- } /*loadappwindowinfo*/
-
-
- boolean savewindow (fname, vnum) bigstring fname; short vnum; {
-
- register hdlappwindow ha = app.appwindow;
- Handle h = nil;
- long ctbytes;
- short rnum;
-
- setstringlength (bserrorstring, 0);
-
- if ((**ha).fnum == 0) { /*file isn't open*/
-
- short fnum;
-
- if (!filenew (fname, vnum, app.creator, app.filetype, &fnum)) {
-
- appalert ("\pError saving the front window.");
-
- return (false);
- }
-
- (**ha).fnum = fnum;
- }
- else { /*file is already open*/
-
- if (!fileseteof ((**ha).fnum, (long) 0)) {
-
- appalert ("\pError truncating the file.");
-
- return (false);
- }
- }
-
- if (!(*app.packcallback) (&h)) {
-
- appalert ("\pOut of memory.");
-
- goto error;
- }
-
- if (!filewritehandle ((**ha).fnum, h)) {
-
- appalert ("\pError writing to file.");
-
- goto error;
- }
-
- if (openresourcefile (fname, vnum, &rnum)) {
-
- tydiskwindowinfo x;
- Handle hoptions = nil;
-
- saveappwindowinfo (ha, &x);
-
- putresource (rnum, 'aptk', 128, longsizeof (x), &x);
-
- (*app.getoptionscallback) (&hoptions);
-
- if (hoptions != nil)
- putresourcehandle (rnum, 'aptk', 129, hoptions);
-
- disposehandle (hoptions);
-
- closeresourcefile (rnum);
- }
-
- disposehandle (h);
-
- (**ha).flmadechanges = false;
-
- return (true);
-
- error:
-
- disposehandle (h);
-
- /*commented dw 8/8/92 -- seems wrong, haven't tested change.
-
- fileclose ((**ha).fnum);
-
- (**ha).fnum = 0;
-
- filedelete (fname, vnum);
- */
-
- return (false);
- } /*savewindow*/
-
-
- boolean newappwindow (bstitle, flshowwindow) bigstring bstitle; boolean flshowwindow; {
-
- register hdlappwindow ha = app.appwindow;
- register WindowPtr macwindow;
- register short i;
- register boolean flrelative = false;
- short hwindow, vwindow;
- Rect rwindow;
- bigstring bslastword;
- hdlscrollbar vertbar = nil, horizbar = nil;
- boolean fl;
-
- if (ha != nil) { /*seed window position from frontmost window*/
-
- getdesktoprect (ha, &rwindow);
-
- hwindow = rwindow.left + 17;
-
- vwindow = rwindow.top + 17;
-
- flrelative = true;
- }
-
- if (!newclearhandle (longsizeof (tyappwindow), (Handle *) &app.appwindow))
- goto error;
-
- ha = app.appwindow; /*copy into register*/
-
- if (app.usecolor && systemhascolor ()) {
-
- macwindow = GetNewCWindow (128, nil, (WindowPtr) -1);
-
- if (app.exactcolors)
- getcolorpalette (macwindow);
-
- (**ha).flcolorwindow = true;
-
- (**ha).forecolor = blackindex;
-
- (**ha).backcolor = whiteindex;
- }
- else {
- macwindow = GetNewWindow (128, nil, (WindowPtr) -1);
-
- (**ha).flcolorwindow = false;
- }
-
- if (macwindow == nil)
- goto error;
-
- if (app.vertscroll) {
-
- if (!newscrollbar (macwindow, true, &vertbar))
- goto error;
- }
-
- if (app.horizscroll) {
-
- if (!newscrollbar (macwindow, false, &horizbar))
- goto error;
- }
-
- (**ha).vertbar = vertbar;
-
- (**ha).horizbar = horizbar;
-
- if (flrelative) /*position window relative to previous window*/
- MoveWindow (macwindow, hwindow, vwindow, false);
- else
- centerwindow (macwindow, quickdrawglobal (screenBits).bounds);
-
- /*copystring (bstitle, (**ha).fname);*/ /*DW 6/14/92*/
-
- if (app.haspalette) {
-
- hdlpaletterecord hpal;
-
- hpal = newpalette (macwindow, app.ctpaletteicons);
-
- if (hpal == nil)
- goto error;
-
- (**ha).hpalette = hpal;
- }
-
- computewindowinfo (macwindow, ha);
-
- (**ha).macwindow = macwindow;
-
- pushmacport (macwindow);
-
- fl = (*app.newrecordcallback) (); /*this callback is allowed to change window size and pos*/
-
- popmacport ();
-
- if (!fl)
- goto error;
-
- computewindowinfo (macwindow, ha); /*window might have been changed by callback*/
-
- (**ha).appdata = app.appdata; /*copy handle alloc'd by newrecord*/
-
- (*(WindowPeek) macwindow).refCon = (long) ha;
-
- lastword (bstitle, ':', bslastword); /*avoid displaying long paths*/
-
- setappwindowtitle (ha, bslastword);
-
- (**ha).selectioninfo.fldirty = true;
-
- resizeappscrollbars (ha);
-
- resetappscrollbars (ha);
-
- if (flshowwindow) {
-
- showappwindow (ha);
-
- showappscrollbars (ha);
- }
-
- return (true);
-
- error:
-
- if (app.haspalette)
- disposepalette ((hdlpaletterecord) (**ha).hpalette);
-
- disposescrollbar (vertbar);
-
- disposescrollbar (horizbar);
-
- macwindow = (**ha).macwindow;
-
- if (macwindow != nil)
- DisposeWindow (macwindow);
-
- disposehandle ((Handle) ha);
-
- setappwindow (nil);
-
- return (false);
- } /*newappwindow*/
-
-
- boolean newuntitledappwindow (boolean flshowwindow) {
-
- bigstring bstitle;
-
- getuntitledtitle (bstitle);
-
- return (newappwindow (bstitle, flshowwindow));
- } /*newuntitledappwindow*/
-
-
- boolean openwindow (fname, vnum) bigstring fname; short vnum; {
-
- hdlappwindow appwindow;
- register hdlappwindow ha;
- short versionnumber;
- long ctbytes;
- short fnum;
- Handle h;
- short rnum;
- Handle hoptions;
-
- setstringlength (bserrorstring, 0);
-
- if (findbyfile (fname, vnum, &appwindow)) {
-
- appalert ("\pThe file is already open.");
-
- selectappwindow (appwindow);
-
- return (true);
- }
-
- if (!fileopen (fname, vnum, &fnum)) {
-
- appalert ("\pError opening the file.");
-
- return (false);
- }
-
- if (!filereadwholefile (fnum, &h)) {
-
- appalert ("\pError reading from file.");
-
- goto error;
- }
-
- /*the data fork of the file stays open while the user is editing it*/
-
- if (!newappwindow (fname, false)) {
-
- appalert ("\pError creating new window.");
-
- goto error;
- }
-
- ha = app.appwindow; /*copy into register*/
-
- if (openresourcefile (fname, vnum, &rnum)) {
-
- tydiskwindowinfo x;
-
- if (getresource (rnum, 'aptk', 128, longsizeof (x), &x))
- loadappwindowinfo (ha, x); /*resize window, set fields of ha*/
-
- getresourcehandle (rnum, 'aptk', 129, &hoptions);
-
- closeresourcefile (rnum);
- }
-
- if (!(*app.unpackcallback) (h)) {
-
- appalert ("\pError reading from file.");
-
- goto error;
- }
-
- if (hoptions != nil)
- (*app.putoptionscallback) (hoptions);
-
- disposehandle (h);
-
- disposehandle (hoptions);
-
- (**ha).appdata = app.appdata; /*copy from the app to our record*/
-
- (**ha).fnum = fnum;
-
- if (vnum == 0) { /*allow caller to give us full path, we maintain it as vnum, fname*/
-
- bigstring bs;
-
- copystring (fname, bs);
-
- pathtofileinfo (bs, fname, &vnum);
- }
-
- if (vnum == 0) { /*DW 6/13/92*/
-
- bigstring bs;
-
- copystring (fname, bs);
-
- pathtofileinfo (bs, fname, &vnum);
- }
-
- copystring (fname, (**ha).fname);
-
- (**ha).vnum = vnum;
-
- showappwindow (ha);
-
- resetappscrollbars (ha);
-
- showappscrollbars (ha);
-
- invalappwindow (ha, false);
-
- return (true);
-
- error:
-
- disposehandle (h);
-
- disposehandle (hoptions);
-
- fileclose (fnum);
-
- return (false);
- } /*openwindow*/
-
-
- static short appsavedialog (bigstring prompt) {
-
- if (!fldialogsenabled) /*don't save changes*/
- return (2);
-
- sysbeep; /*call attention to the user*/
-
- return (savedialog (prompt));
- } /*appsavedialog*/
-
-
- boolean closewindow (hdlappwindow appwindow, boolean fldialog) {
-
- register hdlappwindow ha = appwindow;
-
- if ((**ha).flmadechanges && fldialog && (!app.notsaveable)) {
-
- bigstring bs;
-
- getappwindowtitle (ha, bs);
-
- switch (appsavedialog (bs)) { /*Save “bs” before closing?*/
-
- case 1: { /*yes*/
- hdlappwindow oldappwindow = app.appwindow;
- boolean fl;
-
- setappwindow (ha);
-
- fl = savefrontwindow ();
-
- setappwindow (oldappwindow);
-
- if (!fl) /*user cancelled save*/
- return (false);
-
- break;
- }
-
- case 2: /*no*/
- break;
-
- case 3: /*cancel*/
- return (false);
-
- break;
- } /*switch*/
- }
-
- setappwindow (ha);
-
- fileclose ((**ha).fnum);
-
- disposeappwindow (ha);
-
- return (true);
- } /*closewindow*/
-
-
- boolean closewindowvisit (appwindow) hdlappwindow appwindow; {
-
- return (closewindow (appwindow, true));
- } /*closewindowvisit*/
-
-
- boolean closeallwindows (void) {
-
- return (visitappwindows (&closewindowvisit));
- } /*closeallwindows*/
-
-
- static boolean invalallwindowsvisit (appwindow) hdlappwindow appwindow; {
-
- invalappwindow (appwindow, false);
-
- return (true);
- } /*invalallwindowsvisit*/
-
-
- boolean invalallwindows (void) {
-
- return (visitappwindows (&invalallwindowsvisit));
- } /*invalallwindows*/
-
-
- static boolean eraseallwindowsvisit (appwindow) hdlappwindow appwindow; {
-
- invalappwindow (appwindow, true);
-
- return (true);
- } /*eraseallwindowsvisit*/
-
-
- boolean eraseallwindows (void) {
-
- return (visitappwindows (&eraseallwindowsvisit));
- } /*eraseallwindows*/
-
-
- boolean saveaswindow (fname, vnum) bigstring fname; short vnum; {
-
- register hdlappwindow ha = app.appwindow;
-
- fileclose ((**ha).fnum); /*close the file if it's open*/
-
- (**ha).fnum = 0;
-
- if (!savewindow (fname, vnum))
- return (false);
-
- copystring (fname, (**ha).fname);
-
- (**ha).vnum = vnum;
-
- setappwindowtitle (ha, fname);
-
- copystring (fname, bstargetwindowname);
-
- return (true);
- } /*saveaswindow*/
-
-
- boolean saveasfrontwindow (void) {
-
- register hdlappwindow ha = app.appwindow;
- bigstring fname;
- short vnum;
-
- if ((**ha).fnum == 0)
- getappwindowtitle (ha, fname);
- else
- copystring ((**ha).fname, fname);
-
- vnum = (**ha).vnum;
-
- if (!sfdialog (true, fname, &vnum, app.filefiltercallback, app.filetype))
- return (false);
-
- return (saveaswindow (fname, vnum));
- } /*saveasfrontwindow*/
-
-
- boolean savefrontwindow (void) {
-
- register hdlappwindow ha = app.appwindow;
-
- if (ha == nil) /*defensive driving*/
- return (false);
-
- if ((**ha).fnum == 0)
- return (saveasfrontwindow ());
-
- return (savewindow ((**ha).fname, (**ha).vnum));
- } /*savefrontwindow*/
-
-
- boolean closefrontwindow (void) {
-
- closewindow (app.appwindow, true);
- } /*closefrontwindow*/
-
-
- boolean openfrontwindow (void) {
-
- bigstring fname;
- short vnum;
-
- if (!sfdialog (false, fname, &vnum, app.filefiltercallback, app.filetype))
- return (false);
-
- return (openwindow (fname, vnum));
- } /*openfrontwindow*/
-
-
- boolean revertfrontwindow (void) {
-
- hdlappwindow ha = app.appwindow;
- bigstring fname;
- short vnum;
-
- copystring ((**ha).fname, fname);
-
- vnum = (**ha).vnum;
-
- if ((**ha).flmadechanges && fldialogsenabled) {
-
- bigstring bs, bstitle;
-
- sysbeep; /*call attention to the user*/
-
- getappwindowtitle (ha, bstitle);
-
- copystring ("\pDiscard changes to “", bs);
-
- pushstring (bstitle, bs);
-
- pushstring ("\p”?", bs);
-
- if (!appconfirm (bs))
- return (false);
-
- (**ha).flmadechanges = false; /*avoid dialog in closewindow call*/
- }
-
- if (!closewindow (ha, fldialogsenabled)) /*user declined to discard changes*/
- return (false);
-
- setfrontglobals (); /*seed new window from frontmost window*/
-
- return (openwindow (fname, vnum));
- } /*revertfrontwindow*/
-
-
- boolean settargetglobals (void) {
-
- /*
- get ready to do an operation on the target window. if the name is empty,
- we do the operation on the frontmost window.
-
- the target window name is set using the 'sett' IAC call.
-
- return an error to the script if the target window doesn't exist.
- */
-
- if (stringlength (bstargetwindowname) == 0) { /*no target has been established*/
-
- if (!setfrontglobals ()) /*no windows are open*/
- goto error;
-
- return (true);
- }
-
- if (!setapptarget (bstargetwindowname))
- goto error;
-
- return (true);
-
- error:
-
- IACreturnerror (nowindowerror, "\pNo window is open.");
-
- return (false); /*no window open, stop processing the message*/
- } /*settargetglobals*/
-
-
- boolean exitmainloop (void) {
-
- flexitmainloop = closeallwindows ();
-
- setfrontglobals (); /*some or all of the windows might now be closed*/
-
- return (true);
- } /*exitmainloop*/
-
-
- static void handleupdate (EventRecord ev) {
-
- register WindowPtr w = (WindowPtr) ev.message;
- hdlappwindow appwindow;
-
- if (!getwindowrefcon (w, (long *) &appwindow))
- return;
-
- updateappwindow (appwindow);
- } /*handleupdate*/
-
-
- static void handleactivate (EventRecord ev) {
-
- register WindowPtr w = (WindowPtr) ev.message;
- register boolean flactivate = ev.modifiers & activeFlag;
- hdlappwindow appwindow;
-
- if (!getwindowrefcon (w, (long *) &appwindow))
- return;
-
- setappwindow (appwindow);
-
- activateappscrollbars (appwindow, flactivate);
-
- appprecallback ();
-
- (*app.activatecallback) (flactivate);
-
- apppostcallback ();
- } /*handleactivate*/
-
-
- static void handledrag (EventRecord ev, WindowPtr w) {
-
- Rect r;
-
- r = quickdrawglobal (screenBits).bounds;
-
- r.top = r.top + getmenubarheight ();
-
- r.left = r.left + dragscreenmargin;
-
- r.right = r.right - dragscreenmargin;
-
- r.bottom = r.bottom - dragscreenmargin;
-
- DragWindow (w, ev.where, &r);
- } /*handledrag*/
-
-
- static void setappwindowfrommacwindow (WindowPtr macwindow) {
-
- hdlappwindow appwindow;
-
- if (!getwindowrefcon (macwindow, (long *) &appwindow))
- return;
-
- setappwindow (appwindow);
- } /*setappwindowfrommacwindow*/
-
-
- static void adjustaftergrow (WindowPtr w, Rect oldportrect) {
-
- /*
- 8/26/92 DW: optimize. we now ask for the old portrect for the window
- and only inval any parts of the window that are newly exposed.
- */
-
- hdlappwindow ha;
-
- setappwindowfrommacwindow (w);
-
- ha = app.appwindow;
-
- computewindowinfo (w, ha);
-
- appprecallback ();
-
- (*app.windowresizecallback) ();
-
- apppostcallback ();
-
- invalscrollbar ((**ha).vertbar);
-
- invalscrollbar ((**ha).horizbar);
-
- resizeappscrollbars (ha);
-
- resetappscrollbars (ha);
-
- /*smart inval*/ {
-
- Rect portrect = (*w).portRect;
- short scrollbarwidth = getscrollbarwidth ();
- Rect r;
-
- r.left = oldportrect.right;
-
- r.right = portrect.right;
-
- r.top = oldportrect.top;
-
- r.bottom = portrect.bottom;
-
- invalrect (r);
-
- r.top = oldportrect.bottom;
-
- r.bottom = portrect.bottom;
-
- r.left = oldportrect.left;
-
- r.right = portrect.right;
-
- invalrect (r);
-
- r = oldportrect;
-
- r.left = r.right - scrollbarwidth;
-
- r.top = r.bottom - scrollbarwidth;
-
- invalrect (r);
-
- r = portrect;
-
- r.left = r.right - scrollbarwidth;
-
- r.top = r.bottom - scrollbarwidth;
-
- invalrect (r);
-
- /*
- invalscrollbar ((**ha).vertbar);
-
- invalscrollbar ((**ha).horizbar);
- */
-
- updateappscrollbars (ha);
- }
-
- /*invalappwindow (ha, false);*/
-
- (**ha).flmadechanges = true; /*we save window size and position*/
-
- updateappwindow (ha); /*DW 8/14/92: experiment*/
- } /*adjustaftergrow*/
-
-
- static void handlegrow (Point pt, WindowPtr w) {
-
- register long x;
- Rect boundsrect;
- Rect r;
- Rect oldportrect = (*w).portRect;
-
- boundsrect.left = minwindowwidth;
-
- boundsrect.top = minwindowheight;
-
- r = quickdrawglobal (screenBits).bounds;
-
- boundsrect.right = r.right - r.left; /*maximum window width*/
-
- boundsrect.bottom = r.bottom - r.top; /*maximum window height*/
-
- x = GrowWindow (w, pt, &boundsrect);
-
- SizeWindow (w, LoWord (x), HiWord (x), false);
-
- if (app.eraseonresize) {
-
- Rect r = (*w).portRect;
-
- pushmacport (w);
-
- pushclip (r);
-
- EraseRect (&r);
-
- InvalRect (&r);
-
- popclip ();
-
- popmacport ();
- }
-
- adjustaftergrow (w, oldportrect);
- } /*handlegrow*/
-
-
- void zoomappwindow (hdlappwindow appwindow) {
-
- register hdlappwindow ha = appwindow;
- register WindowPtr w = (**ha).macwindow;
- register WStateData **hstatedata = (WStateData **) (*(WindowPeek) w).dataHandle;
- Rect rzoomed, rcurrent;
- Rect oldportrect = (*w).portRect;
- short part;
-
- getdesktoprect (ha, &rcurrent);
-
- rzoomed = (**hstatedata).stdState; /*default*/
-
- if (!optionkeydown ()) { /*allow option key to over-ride "smart" zoom*/
-
- boolean fl;
-
- appprecallback ();
-
- fl = (*app.getcontentsizecallback) ();
-
- apppostcallback ();
-
- if (fl) {
-
- register short height = (**ha).zoomheight;
- register short width = (**ha).zoomwidth;
- Rect r;
-
- if (app.statuspixels > 0)
- height += app.statuspixels + 3; /*a 3-pixel line separates status & content*/
-
- width += (**ha).contentrect.left;
-
- /*allow for scrollbars and/or grow icon*/ {
-
- register short scrollbarwidth = getscrollbarwidth ();
-
- if (app.horizscroll)
- height += scrollbarwidth;
-
- if (app.vertscroll)
- width += scrollbarwidth;
- }
-
- /*allow for the window's title*/ {
-
- bigstring bs;
- short titlewidth;
-
- pushstyle (systemFont, 12, normal);
-
- getappwindowtitle (ha, bs);
-
- titlewidth = StringWidth (bs) + 64;
-
- if (width < titlewidth)
- width = titlewidth;
-
- popstyle ();
- }
-
- if (width < minwindowwidth)
- width = minwindowwidth;
-
- if (height < minwindowheight)
- height = minwindowheight;
-
- r = rcurrent;
-
- r.right = r.left + width;
-
- r.bottom = r.top + height;
-
- constraintodesktop (&r);
-
- rzoomed = r;
- }
- }
-
- if (equalrects (rzoomed, rcurrent))
- part = inZoomIn;
- else {
- short minscroll, maxscroll, currentscroll;
-
- (**hstatedata).stdState = rzoomed;
-
- getscrollbarinfo ((**ha).vertbar, &minscroll, &maxscroll, ¤tscroll);
-
- setscrollbarcurrent ((**ha).vertbar, minscroll);
-
- getscrollbarinfo ((**ha).horizbar, &minscroll, &maxscroll, ¤tscroll);
-
- setscrollbarcurrent ((**ha).horizbar, minscroll);
-
- appprecallback ();
-
- (*app.scrolltocallback) ();
-
- apppostcallback ();
-
- part = inZoomOut;
- }
-
- /*invalappwindow (ha, app.eraseonresize);*/ /*erase the window contents and inval it*/
-
- ZoomWindow (w, part, true);
-
- adjustaftergrow (w, oldportrect);
- } /*zoomappwindow*/
-
-
- static void undocommand (void) {
- } /*undocommand*/
-
-
- static boolean pushscrap (Handle h, OSType type) {
-
- OSErr ec;
-
- if (h == nil)
- return (true);
-
- lockhandle (h);
-
- ec = PutScrap (GetHandleSize (h), type, *h);
-
- unlockhandle (h);
-
- if (ec != noErr) {
-
- appalert ("\pError copying to clipboard.");
-
- return (false);
- }
-
- return (true);
- } /*pushscrap*/
-
-
- static void copycommand (void) {
-
- Handle appscrap = nil, textscrap = nil, pictscrap = nil;
- boolean flhavescrap = false;
- OSErr ec;
-
- if ((*app.copycallback) (&appscrap))
- flhavescrap = true;
-
- (*app.gettextcallback) (&textscrap); /*textscrap is nil if it failed*/
-
- if (textscrap != nil)
- flhavescrap = true;
-
- (*app.getpictcallback) (&pictscrap); /*pictscrap is nil if it failed*/
-
- if (pictscrap != nil)
- flhavescrap = true;
-
- if (!flhavescrap) {
-
- appalert ("\pNothing to copy.");
-
- return;
- }
-
- ZeroScrap ();
-
- if (!pushscrap (appscrap, app.creator)) /*error message already set/displayed*/
- return;
-
- if (!pushscrap (textscrap, 'TEXT'))
- return;
-
- pushscrap (pictscrap, 'PICT');
- } /*copycommand*/
-
-
- static void clearcommand (void) {
-
- appprecallback ();
-
- (*app.clearcallback) ();
-
- apppostcallback ();
- } /*clearcommand*/
-
-
- static void pastecommand (void) {
-
- Handle hscrap;
- long offset, ctbytes;
-
- clearcommand ();
-
- hscrap = NewHandle (0);
-
- ctbytes = GetScrap (hscrap, app.creator, &offset);
-
- if (ctbytes > 0) {
-
- boolean fl;
-
- appprecallback ();
-
- fl = (*app.pastecallback) (hscrap);
-
- apppostcallback ();
-
- if (fl) {
-
- DisposeHandle (hscrap);
-
- return;
- }
-
- DisposeHandle (hscrap);
-
- hscrap = NewHandle (0);
- }
-
- ctbytes = GetScrap (hscrap, 'PICT', &offset);
-
- if (ctbytes > 0) {
-
- boolean fl;
-
- appprecallback ();
-
- fl = (*app.putpictcallback) (hscrap);
-
- apppostcallback ();
-
- if (fl)
- return;
-
- DisposeHandle (hscrap); /*app didn't want the PICT*/
-
- hscrap = NewHandle (0);
- }
-
- ctbytes = GetScrap (hscrap, 'TEXT', &offset);
-
- if (ctbytes > 0) {
-
- boolean fl;
-
- appprecallback ();
-
- fl = (*app.puttextcallback) (hscrap);
-
- apppostcallback ();
-
- if (fl)
- return;
-
- DisposeHandle (hscrap);
-
- hscrap = NewHandle (0);
- }
-
- if (hscrap != nil)
- DisposeHandle (hscrap);
- } /*pastecommand*/
-
-
- static void cutcommand (void) {
-
- copycommand ();
-
- clearcommand ();
- } /*cutcommand*/
-
-
- static boolean selectallcommand (void) {
-
- boolean fl;
-
- appprecallback ();
-
- fl = (*app.selectallcallback) ();
-
- apppostcallback ();
-
- return (fl);
- } /*selectallcommand*/
-
-
- static void appsetfont (bigstring fontname) {
-
- register hdlappwindow ha = app.appwindow;
- short fontnumber;
-
- GetFNum (fontname, &fontnumber);
-
- (**ha).selectioninfo.fontnum = fontnumber;
-
- appprecallback ();
-
- (*app.setfontcallback) ();
-
- apppostcallback ();
-
- (**ha).selectioninfo.fldirty = true;
-
- (**ha).defaultfont = fontnumber; /*side-effect, 7/6/92 DW*/
- } /*appsetfont*/
-
-
- static void appsetfontsize (short size) {
-
- register hdlappwindow ha = app.appwindow;
-
- (**ha).selectioninfo.fontsize = size;
-
- appprecallback ();
-
- (*app.setsizecallback) ();
-
- apppostcallback ();
-
- (**ha).selectioninfo.fldirty = true;
-
- (**ha).defaultsize = size; /*side-effect, 7/6/92 DW*/
- } /*appsetfontsize*/
-
-
- static void handlemenu (long codeword) {
-
- register hdlappwindow ha = app.appwindow;
- register short idmenu, iditem;
- boolean fl;
-
- iditem = LoWord (codeword);
-
- if (iditem <= 0)
- goto exit;
-
- idmenu = HiWord (codeword);
-
- if (SharedMenuHit (idmenu, iditem))
- goto exit;
-
- appprecallback ();
-
- fl = (*app.menucallback) (idmenu, iditem);
-
- apppostcallback ();
-
- if (fl) /*consumed by the app*/
- goto exit;
-
- switch (idmenu) {
-
- case applemenu:
- switch (iditem) {
-
- case aboutitem:
- aboutcommand ();
-
- break;
-
- default: {
-
- bigstring bs;
-
- GetItem (hdlapplemenu, iditem, bs);
-
- OpenDeskAcc (bs);
-
- break;
- }
- } /*switch*/
-
- break; /*apple menu*/
-
- case filemenu:
- switch (iditem) {
-
- case newitem:
- newuntitledappwindow (true);
-
- break;
-
- case openitem:
- openfrontwindow ();
-
- break;
-
- case closeitem:
- if (optionkeydown ())
- closeallwindows ();
- else
- closefrontwindow ();
-
- break;
-
- case saveitem:
- savefrontwindow ();
-
- break;
-
- case saveasitem:
- saveasfrontwindow ();
-
- break;
-
- case revertitem:
- revertfrontwindow ();
-
- break;
-
- case pagesetupitem:
- pagesetup ();
-
- break;
-
- case printitem:
- printappwindow (ha, true);
-
- break;
-
- case quititem:
- exitmainloop ();
-
- break;
- } /*switch*/
-
- break; /*file menu*/
-
- case editmenu:
- switch (iditem) {
-
- case undoitem:
- undocommand ();
-
- break;
-
- case cutitem:
- cutcommand ();
-
- break;
-
- case copyitem:
- copycommand ();
-
- break;
-
- case pasteitem:
- pastecommand ();
-
- break;
-
- case clearitem:
- clearcommand ();
-
- break;
-
- case selectallitem:
- selectallcommand ();
-
- break;
- } /*switch*/
-
- break; /*edit menu*/
-
- case fontmenu: {
-
- bigstring bs;
-
- getmenuitem (hdlfontmenu, iditem, bs);
-
- appsetfont (bs);
-
- break;
- } /*font menu*/
-
- case sizemenu: {
-
- short size = (**ha).selectioninfo.fontsize;
-
- switch (iditem) {
-
- case point9item:
- size = 9;
-
- break;
-
- case point10item:
- size = 10;
-
- break;
-
- case point12item:
- size = 12;
-
- break;
-
- case point14item:
- size = 14;
-
- break;
-
- case point18item:
- size = 18;
-
- break;
-
- case point24item:
- size = 24;
-
- break;
-
- case point36item:
- size = 36;
-
- break;
-
- case point48item:
- size = 48;
-
- break;
-
- case point72item:
- size = 72;
-
- break;
-
- case pointupitem:
- size++;
-
- break;
-
- case pointdownitem:
- size--;
-
- if (size < 1)
- size = 1;
-
- break;
-
- case pointcustomitem: {
- bigstring bs;
- long num;
-
- NumToString (size, bs);
-
- if (!askdialog ("\pCustom font size:", bs))
- goto exit;
-
- StringToNum (bs, &num); /*no protection against non-numeric chars*/
-
- size = (short) num;
-
- break;
- }
- } /*switch*/
-
- if (size != 0)
- appsetfontsize (size);
-
- break;
- } /*size menu*/
-
- case stylemenu: {
-
- tyselectioninfo x = (**ha).selectioninfo;
-
- clearbytes (&x, longsizeof (x)); /*init all fields to zero*/
-
- x.flplain = false; /*it's off unless plain was selected*/
-
- switch (iditem) {
-
- case plainitem:
- x.flplain = true;
-
- break;
-
- case bolditem:
- x.flbold = true;
-
- break;
-
- case italicitem:
- x.flitalic = true;
-
- break;
-
- case underlineitem:
- x.flunderline = true;
-
- break;
-
- case outlineitem:
- x.floutline = true;
-
- break;
-
- case shadowitem:
- x.flshadow = true;
-
- break;
- } /*switch*/
-
- setselectionstyleinfo (&x, true); /*pack into bits of x.fontstyle*/
-
- (**ha).selectioninfo = x;
-
- appprecallback ();
-
- (*app.setstylecallback) ();
-
- apppostcallback ();
-
- (**ha).selectioninfo.fldirty = true;
-
- break;
- } /*style menu*/
-
- case justifymenu: {
-
- register tyjustification justification = unknownjustification;
-
- switch (iditem) {
-
- case leftjustifyitem:
- justification = leftjustified;
-
- break;
-
- case centerjustifyitem:
- justification = centerjustified;
-
- break;
-
- case rightjustifyitem:
- justification = rightjustified;
-
- break;
-
- case fulljustifyitem:
- justification = fulljustified;
-
- break;
-
- } /*switch*/
-
- if (justification != unknownjustification) {
-
- (**ha).selectioninfo.justification = justification;
-
- appprecallback ();
-
- (*app.setjustifycallback) ();
-
- apppostcallback ();
-
- (**ha).selectioninfo.fldirty = true;
- }
-
- break;
- } /*justify menu*/
-
- } /*switching on which menu was invoked*/
-
- exit:
-
- HiliteMenu (0);
- } /*handlemenu*/
-
-
- static void handlekeystroke (EventRecord ev) {
-
- register char ch = ev.message & charCodeMask;
- register boolean flcmdkey = ev.modifiers & cmdKey;
-
- flcmdperiod = flcmdkey && (ch == '.'); /*set global*/
-
- if (SharedScriptRunning ()) { /*cmd-period terminates the script*/
-
- if (flcmdperiod) {
-
- CancelSharedScript (); /*cancel the shared menu script, if one is running*/
-
- return;
- }
- }
-
- if (flcmdkey) {
-
- handlemenu (MenuKey (ch));
-
- return;
- }
-
- setkeyboardstatus (ev);
-
- if (app.appwindow != nil) {
-
- appprecallback ();
-
- (*app.keystrokecallback) ();
-
- apppostcallback ();
- }
- } /*handlekeystroke*/
-
-
- static void handlecontent (EventRecord ev, WindowPtr w) {
-
- register hdlappwindow ha = app.appwindow;
- Point pt = ev.where;
- hdlscrollbar scrollbar;
- short part;
-
- globaltolocalpoint (w, &pt);
-
- if (findscrollbar (pt, w, &scrollbar, &part)) {
-
- handlescrollbar (scrollbar == (**ha).vertbar, scrollbar, part, pt);
-
- return;
- }
-
- /*send mouse hit to the applet*/
-
- mousestatus.localpt = pt;
-
- mousestatus.fldoubleclick = mousedoubleclick (ev.where);
-
- if (PtInRect (pt, &(**ha).contentrect)) {
-
- mousestatus.localpt.h += (**ha).scrollorigin.h;
-
- mousestatus.localpt.v += (**ha).scrollorigin.v;
-
- setkeyboardstatus (ev); /*applet can tell if shift key is down, other modifiers*/
-
- appprecallback ();
-
- (*app.mousecallback) ();
-
- apppostcallback ();
- }
-
- if (PtInRect (pt, &(**ha).statusrect)) {
-
- pushclip ((**ha).statusrect);
-
- (*app.mouseinstatuscallback) ();
-
- popclip ();
- }
-
- if (app.haspalette) {
-
- if (PtInRect (pt, &(**(**ha).hpalette).r))
- palettemousedown ((**ha).hpalette);
- }
- } /*handlecontent*/
-
-
- static void handlemouseup (EventRecord ev) {
-
- /*
- call this when you receive an mouse up event. if the last mouse down was
- a double click, we set things up so that the next single click will not
- be interpreted as a double click.
- */
-
- if (!mousestatus.fldoubleclickdisabled) {
-
- mousestatus.mouseuptime = ev.when;
-
- mousestatus.mouseuppoint = ev.where;
-
- mousestatus.mousedowntime = 0L; /*hasn't happened yet*/
- }
-
- mousestatus.fldoubleclickdisabled = false; /*next mouse up is important*/
- } /*handlemouseup*/
-
-
- static void handlemousedown (EventRecord ev) {
-
- short part;
- WindowPtr w;
-
- mousestatus.mousedowntime = ev.when; /*set globals so we can detect a 2click*/
-
- mousestatus.mousedownpoint = ev.where;
-
- part = FindWindow (ev.where, &w);
-
- switch (part) {
-
- case inMenuBar:
- handlemenu (MenuSelect (ev.where));
-
- break;
-
- case inContent:
- if (w != nil) {
-
- if (w != FrontWindow ()) { /*just like all other Mac programs*/
-
- SelectWindow (w);
-
- return; /*the mouse click is consumed by the bringtofront operation*/
- }
- }
-
- handlecontent (ev, w);
-
- break;
-
- case inSysWindow:
- SystemClick (&ev, w);
-
- break;
-
- case inDrag:
- handledrag (ev, w);
-
- break;
-
- case inGrow:
- handlegrow (ev.where, w);
-
- break;
-
- case inGoAway:
- if (TrackGoAway (w, ev.where)) {
-
- if (optionkeydown ())
- closeallwindows ();
- else
- closefrontwindow ();
- }
-
- break;
-
- case inZoomOut: case inZoomIn:
- if (TrackBox (w, ev.where, part))
- zoomappwindow (app.appwindow);
-
- break;
-
- } /*switch*/
- } /*handlemousedown*/
-
-
- static boolean jugglervisit (hdlappwindow appwindow) {
-
- register hdlappwindow ha = appwindow;
- register boolean fl = flcurrentlyactive && ((**ha).macwindow == FrontWindow ());
-
- setappwindow (ha);
-
- activateappscrollbars (ha, fl);
-
- appprecallback ();
-
- (*app.activatecallback) (fl);
-
- apppostcallback ();
-
- drawappgrowicon (ha);
- } /*jugglervisit*/
-
-
- static void handlejuggler (EventRecord ev) {
-
- register boolean flresume;
- tyjugglermessage jmsg;
-
- moveleft (&ev.message, &jmsg, longsizeof (jmsg));
-
- if (jmsg.eventtype == 1) { /*suspend or resume subevent*/
-
- flresume = jmsg.flresume; /*copy into register*/
-
- if (jmsg.flconvertclipboard) { /*11/3/91 DW: get to this later*/
- }
-
- appprecallback ();
-
- (*app.resumecallback) (flresume);
-
- apppostcallback ();
-
- flcurrentlyactive = flresume; /*set global before visit*/
-
- visitappwindows (&jugglervisit); /*send message to all open windows*/
- }
- } /*handlejuggler*/
-
-
- static boolean handledialogevent (EventRecord event) {
-
- /*
- if the event belongs to a dialog, allow it to be processed in
- the standard way. the applet toolkit doesn't currently support the
- creation of modeless dialogs, but we must be a host to them anyway.
- */
-
- DialogPtr dlog;
- short itemnumber;
-
- if (!IsDialogEvent (&event))
- return (false);
-
- DialogSelect (&event, &dlog, &itemnumber);
-
- return (true);
- } /*handledialogevent*/
-
-
- static void handleevent (EventRecord ev) {
-
- if (handledialogevent (ev))
- return;
-
- switch (ev.what) {
-
- case keyDown: case autoKey:
- handlekeystroke (ev);
-
- break;
-
- case mouseDown:
- handlemousedown (ev);
-
- break;
-
- case mouseUp:
- handlemouseup (ev);
-
- break;
-
- case activateEvt:
- handleactivate (ev);
-
- break;
-
- case jugglerEvt:
- handlejuggler (ev);
-
- break;
-
- case updateEvt:
- handleupdate (ev);
-
- break;
-
- case nullEvent:
- resetdirtyscrollbars ();
-
- if (flcurrentlyactive)
- CheckSharedMenus (firstsharedmenu);
-
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent (&ev);
-
- break;
- } /*switch*/
- } /*handleevent*/
-
-
- static void appidle (void) {
-
- appprecallback ();
-
- (*app.idlecallback) ();
-
- apppostcallback ();
- } /*appidle*/
-
-
- static pascal short appwaitroutine (EventRecord *ev) {
-
- /*
- we're called by the IAC Toolkit while it's waiting for a reply to an
- Apple Event. since we may be called while getting new shared menus, we
- must not call handleevent for null events here to avoid re-entrancy
- */
-
- if ((*ev).what == nullEvent)
- appidle ();
- else
- handleevent (*ev);
-
- return (0);
- } /*appwaitroutine*/
-
-
- boolean maineventhandler (ev) EventRecord ev; {
-
- /*
- if you have an event, and have determined that it's not for you, pass it
- thru this routine for processing.
-
- we check to see if our Frontier-supplied menus need to be re-installed.
- this can happen if a script-writer is making editing changes over in Frontier.
- by waiting for real events, we eliminate very annoying delays when editing
- in Frontier.
-
- returns false if you should break out of your loop, true if you should
- keep looping.
- */
-
- IACglobals.waitroutine = &appwaitroutine; /*for waiting after sending an Apple Event*/
-
- setfrontglobals (); /*event applies to frontmost window*/
-
- GetMouse (&mousestatus.localpt);
-
- adjustmenus ();
-
- appidle ();
-
- handleevent (ev); /*might set flexitmainloop true*/
-
- return (!flexitmainloop);
- } /*maineventhandler*/
-
-
- void maineventloop (void) {
-
- EventRecord ev;
-
- while (!flexitmainloop) {
-
- WaitNextEvent (everyEvent, &ev, 1, nil);
-
- appletevent = ev; /*set global, can be accessed by anyone with an interest*/
-
- maineventhandler (ev);
- } /*while*/
- } /*maineventloop*/
-
-
- boolean serviceeventqueue (void) {
-
- /*
- pop and process all waiting events, return true when we get to a null
- event. return false if the user selected the quit command, or otherwise
- wants the program to terminate.
-
- 8/8/92 DW: return false also if the user presses cmd-period.
- */
-
- EventRecord ev;
-
- flcmdperiod = false;
-
- while (!flexitmainloop) {
-
- WaitNextEvent (everyEvent, &ev, 1, nil);
-
- if (ev.what == nullEvent) /*got all the meaningful events*/
- return (true);
-
- maineventhandler (ev);
-
- if (flcmdperiod) {
-
- /*sysbeep;*/
-
- return (false);
- }
- } /*while*/
-
- return (false); /*user must have selected the quit command*/
- } /*serviceeventqueue*/
-
-
- static boolean setwindowtitleverb (void) {
-
- /*
- verb that sets the window title of the target window.
- */
-
- bigstring bs;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- setappwindowtitle (app.appwindow, bs);
-
- copystring (bs, bstargetwindowname);
-
- return (IACreturnboolean (true));
- } /*setwindowtitleverb*/
-
-
- static boolean getwindowrectverb (void) {
-
- register hdlappwindow ha = app.appwindow;
- Rect r = (**app.appwindow).contentrect;
-
- OffsetRect (&r, (**ha).scrollorigin.h, (**ha).scrollorigin.v);
-
- return (IACreturnrect (&r));
- } /*getwindowrectverb*/
-
-
- static boolean closewindowverb (void) {
-
- /*
- verb that closes an existing window. it takes no parameters, the
- current target window is closed.
-
- 8/25/92 DW: if we close the target window, reset the target to the
- frontmost window.
- */
-
- boolean fl = false;
- hdlappwindow ha;
- boolean flresettarget;
-
- flresettarget = stringlength (bstargetwindowname) > 0;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- ha = app.appwindow;
-
- if (ha != nil) { /*a window is open*/
-
- fl = closewindow (ha, fldialogsenabled);
-
- if (fl && flresettarget)
- setstringlength (bstargetwindowname, 0);
- }
-
- return (IACreturnboolean (fl));
- } /*closewindowverb*/
-
-
- static boolean revertverb (void) {
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- return (IACreturnboolean (revertfrontwindow ()));
- } /*revertverb*/
-
-
- static boolean zoomwindowverb (void) {
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- zoomappwindow (app.appwindow);
-
- return (IACreturnboolean (true));
- } /*zoomwindowverb*/
-
-
- static boolean scrollwindowverb (void) {
-
- short x;
- tydirection dir;
- short ct;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgetshortparam ('dire', &x))
- return (false);
-
- dir = (tydirection) x;
-
- if (!IACgetshortparam ('coun', &ct))
- return (false);
-
- scrollappwindow (dir, false, ct);
-
- return (IACreturnboolean (true));
- } /*scrollwindowverb*/
-
-
- static boolean saveasverb (void) {
-
- register boolean fl = false;
- bigstring path;
- bigstring fname;
- short vnum;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgetstringparam (keyDirectObject, path))
- return (false);
-
- if (stringlength (path) == 0) {
-
- fl = savefrontwindow ();
- }
- else {
- if (pathtofileinfo (path, fname, &vnum))
- fl = saveaswindow (fname, vnum);
- }
-
- return (IACreturnboolean (fl));
- } /*saveasverb*/
-
-
- static boolean openverb (void) {
-
- register boolean fl = false;
- bigstring path;
- bigstring fname;
- short vnum;
-
- setstringlength (bserrorstring, 0);
-
- if (!IACgetstringparam (keyDirectObject, path))
- return (false);
-
- if (!pathtofileinfo (path, fname, &vnum))
- appalert ("\pError opening the file.");
- else
- fl = openwindow (fname, vnum);
-
- return (IACreturnboolean (fl));
- } /*openverb*/
-
-
- static boolean nthwindowverb (void) {
-
- bigstring bs;
- short n;
- hdlappwindow appwindow;
-
- if (!IACgetshortparam (keyDirectObject, &n))
- return (false);
-
- findnthwindow (n, &appwindow);
-
- getappwindowtitle (appwindow, bs);
-
- return (IACreturnstring (bs));
- } /*nthwindowverb*/
-
-
- static boolean selectwindowverb (void) {
-
- /*
- verb that brings a window to the front, you provide the name of the window in
- a string parameter. side effect -- it also sets the target to that window.
- */
-
- register boolean fl = false;
- bigstring bs;
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- if (selectwindowbytitle (bs)) {
-
- fl = true;
-
- copystring (bs, bstargetwindowname);
- }
-
- return (IACreturnboolean (fl));
- } /*selectwindowverb*/
-
-
- static boolean perftestverb (void) {
-
- /*
- this verb supports a performance benchmark script written in Frontier.
-
- 6/28/91 DW: perform rectangle subtraction on two rectangle params,
- return the difference.
- */
-
- Rect r1, r2, r;
-
- if (!IACgetrectparam ('prm1', &r1))
- return (false);
-
- if (!IACgetrectparam ('prm2', &r2))
- return (false);
-
- r.top = r1.top - r2.top;
-
- r.left = r1.left - r2.left;
-
- r.bottom = r1.bottom - r2.bottom;
-
- r.right = r1.right - r2.right;
-
- return (IACreturnrect (&r));
- } /*perftestverb*/
-
-
- static boolean alertdialogverb (void) {
-
- /*
- opens up a modal dialog box with the string parameter displayed, wait for
- the user to click on OK before returning the value.
-
- to support runtime menus, you wire your dialog boxes to IAC events if you want
- script writers to be able to transparently talk to the user without Frontier
- coming to the front.
- */
-
- bigstring bs;
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- return (IACreturnboolean (appalert (bs)));
- } /*alertdialogverb*/
-
-
- static boolean confirmdialogverb (void) {
-
- /*
- opens up a modal dialog box with the string parameter displayed, wait for
- the user to click on OK before returning the value.
-
- to support runtime menus, you wire your dialog boxes to IAC events if you want
- script writers to be able to transparently talk to the user without Frontier
- coming to the front.
- */
-
- bigstring bs;
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- return (IACreturnboolean (appconfirm (bs)));
- } /*confirmdialogverb*/
-
-
- static boolean askdialogverb (void) {
-
- /*
- to support runtime menus, you wire your dialog boxes to IAC events if you want
- script writers to be able to transparently talk to the user without Frontier
- coming to the front.
- */
-
- bigstring prompt, answer;
- boolean fl;
-
- if (!IACgetstringparam (keyDirectObject, prompt))
- return (false);
-
- if (!IACgetstringparam ('dflt', answer))
- return (false);
-
- fl = appask (prompt, answer);
-
- IACglobals.event = IACglobals.reply; /*push the params onto the reply record*/
-
- if (!IACpushstringparam (answer, 'ansr'))
- return (false);
-
- return (IACreturnboolean (fl));
- } /*askdialogverb*/
-
-
- static boolean settargetverb (void) {
-
- /*
- set the target of all subsequent verbs to the window named by the string
- parameter.
-
- special case: set the target string to the empty string if you want verbs
- to apply to the frontmost window.
-
- returns the title of the target window.
- */
-
- register boolean fl = true;
- bigstring bs;
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- if (stringlength (bs) == 0) { /*special case*/
-
- if (setfrontglobals ())
- getappwindowtitle (app.appwindow, bs);
- }
-
- else {
- if (!setapptarget (bs))
- setstringlength (bs, 0);
- }
-
- copystring (bs, bstargetwindowname);
-
- return (IACreturnstring (bs));
- } /*settargetverb*/
-
-
- static boolean gettargetverb (void) {
-
- /*
- returns the title of the target window.
- */
-
- bigstring bs;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- getappwindowtitle (app.appwindow, bs);
-
- return (IACreturnstring (bs));
- } /*gettargetverb*/
-
-
- static boolean newwindowverb (void) {
-
- register boolean fl = false;
- hdlappwindow appwindow;
- bigstring bs;
- long ctbars;
-
- setstringlength (bserrorstring, 0);
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- if (stringlength (bs) == 0)
- getuntitledtitle (bs);
-
- if (findbywindowtitle (bs, &appwindow)) {
-
- appalert ("\pA window with that name is already open.");
-
- setstringlength (bs, 0); /*return the empty string to indicate error*/
- }
- else {
- if (newappwindow (bs, true)) {
-
- fl = true;
-
- copystring (bs, bstargetwindowname);
- }
- }
-
- return (IACreturnstring (bs));
- } /*newwindowverb*/
-
-
- static boolean madechangesverb (void) {
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- IACreturnboolean ((**app.appwindow).flmadechanges);
- } /*madechangesverb*/
-
-
- static boolean countwindowsverb (void) {
-
- return (IACreturnshort (countwindows ()));
- } /*countwindowsverb*/
-
-
- static boolean selectallverb (void) {
-
- register boolean fl;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- fl = selectallcommand ();
-
- return (IACreturnboolean (fl));
- } /*selectallverb*/
-
-
- static boolean haveselectionverb (void) {
-
- register boolean fl;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- fl = (*app.haveselectioncallback) ();
-
- return (IACreturnboolean (fl));
- } /*haveselectionverb*/
-
-
- static boolean setfontverb (void) {
-
- bigstring bs;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgetstringparam (keyDirectObject, bs))
- return (false);
-
- appsetfont (bs);
-
- return (IACreturnboolean (true));
- } /*setfontverb*/
-
-
- static boolean setfontsizeverb (void) {
-
- short fontsize;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgetshortparam (keyDirectObject, &fontsize))
- return (false);
-
- appsetfontsize (fontsize);
-
- return (IACreturnboolean (true));
- } /*setfontsizeverb*/
-
-
- static boolean printwindowverb (void) {
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- return (IACreturnboolean (printappwindow (app.appwindow, false)));
- } /*printwindowverb*/
-
-
- static boolean enablealertverb (void) {
-
- register boolean fl;
- Boolean flenabled;
-
- if (!IACgetbooleanparam (keyDirectObject, &flenabled))
- return (false);
-
- fl = fldialogsenabled; /*return the original value, per spec*/
-
- fldialogsenabled = flenabled;
-
- return (IACreturnboolean (fl));
- } /*enablealertverb*/
-
-
- static boolean quitverb (void) {
-
- return (IACreturnboolean (exitmainloop ()));
- } /*quitverb*/
-
-
- static boolean geterrorstringverb (void) {
-
- return (IACreturnstring (bserrorstring));
- } /*geterrorstringverb*/
-
-
- static boolean movewindowverb (void) {
-
- Rect r;
- WindowPtr w;
- Rect oldportrect;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- w = (**app.appwindow).macwindow;
-
- oldportrect = (*w).portRect;
-
- if (!IACgetrectparam (keyDirectObject, &r))
- return (false);
-
- moveappwindow (app.appwindow, r);
-
- adjustaftergrow (w, oldportrect);
-
- return (IACreturnboolean (true));
- } /*movewindowverb*/
-
-
- static boolean getfilepathverb (void) {
-
- register hdlappwindow ha;
- bigstring path;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- ha = app.appwindow;
-
- if ((**ha).fnum == 0) /*no file open*/
- setemptystring (path);
- else
- fileinfotopath ((**ha).fname, (**ha).vnum, path);
-
- return (IACreturnstring (path));
- } /*getfilepathverb*/
-
-
- static boolean getpictverb (void) {
-
- Handle hpict;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- hpict = nil;
-
- (*app.getpictcallback) (&hpict); /*hpict is nil if it failed*/
-
- return (IACreturnbinary (hpict, 'PICT'));
- } /*getpictverb*/
-
-
- static boolean gettextverb (void) {
-
- Handle htext;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- htext = nil;
-
- (*app.gettextcallback) (&htext); /*htext is nil if it failed*/
-
- return (IACreturnbinary (htext, 'TEXT'));
- } /*gettextverb*/
-
-
- static boolean putpictverb (void) {
-
- Handle hpict;
- register boolean fl;
- OSType binarytype;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgetbinaryparam (keyDirectObject, &hpict, &binarytype))
- return (false);
-
- fl = (*app.putpictcallback) (hpict);
-
- return (IACreturnboolean (fl));
- } /*putpictverb*/
-
-
- static boolean puttextverb (void) {
-
- Handle htext;
- register boolean fl;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- if (!IACgettextparam (keyDirectObject, &htext))
- return (false);
-
- fl = (*app.puttextcallback) (htext);
-
- return (IACreturnboolean (fl));
- } /*puttextverb*/
-
-
- static boolean getbinaryverb (void) {
-
- AEDesc desc;
- OSErr ec;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- desc.dataHandle = nil;
-
- desc.descriptorType = app.filetype;
-
- (*app.packcallback) (&desc.dataHandle);
-
- ec = AEPutParamDesc (IACglobals.reply, keyDirectObject, &desc);
-
- AEDisposeDesc (&desc);
-
- return (true);
- } /*getbinaryverb*/
-
-
- static boolean putbinaryverb (void) {
-
- AEDesc result;
- OSErr ec;
- Handle h;
- register boolean fl;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- ec = AEGetParamDesc (IACglobals.event, keyDirectObject, app.filetype, &result);
-
- fl = (*app.unpackcallback) (result.dataHandle);
-
- AEDisposeDesc (&result);
-
- return (IACreturnboolean (fl));
- } /*putbinaryverb*/
-
-
- static boolean getpagerectverb (void) {
-
- getprintinfo ();
-
- return (IACreturnrect (&app.printinfo.paperrect));
- } /*getpagerectverb*/
-
-
- static boolean getwindowposverb (void) {
-
- Rect r;
-
- if (!settargetglobals ()) /*this verb requires an open window*/
- return (false);
-
- r = (**app.appwindow).windowrect;
-
- localtoglobalrect (&r);
-
- return (IACreturnrect (&r));
- } /*getwindowposverb*/
-
-
- static pascal OSErr handlecustomverb (AppleEvent *event, AppleEvent *reply, long refcon) {
-
- if (SharedScriptCancelled (event, reply))
- return (noErr);
-
- IACglobals.event = event;
-
- IACglobals.reply = reply;
-
- IACglobals.refcon = refcon;
-
- appprecallback ();
-
- (*app.iacmessagecallback) ();
-
- apppostcallback ();
-
- return (noErr);
- } /*handlecustomverb*/
-
-
- static pascal OSErr handlefastverb (AppleEvent *event, AppleEvent *reply, long refcon) {
-
- if (SharedScriptCancelled (event, reply))
- return (noErr);
-
- IACglobals.event = event;
-
- IACglobals.reply = reply;
-
- IACglobals.refcon = refcon;
-
- appprecallback ();
-
- (*app.iacfastmessagecallback) ();
-
- apppostcallback ();
-
- return (noErr);
- } /*handlefastverb*/
-
-
- static pascal OSErr handleapp1verb (AppleEvent *event, AppleEvent *reply, long refcon) {
-
- /*
- called by Apple Event Manager when an 'app1' verb arrives.
-
- we always return noErr to the Apple Event Manager -- each verb processor
- may set the error number and string in the reply record by calling
- IACreturnerror.
- */
-
- if (SharedScriptCancelled (event, reply))
- return (noErr);
-
- IACglobals.event = event;
-
- IACglobals.reply = reply;
-
- IACglobals.refcon = refcon;
-
- switch (IACgetverbtoken ()) {
-
- case newwindowtoken:
- newwindowverb (); break;
-
- case closewindowtoken:
- closewindowverb (); break;
-
- case savewindowtoken:
- saveasverb (); break;
-
- case revertwindowtoken:
- revertverb (); break;
-
- case openwindowtoken:
- openverb (); break;
-
- case gettargettoken:
- gettargetverb (); break;
-
- case selectwindowtoken:
- selectwindowverb (); break;
-
- case zoomwindowtoken:
- zoomwindowverb (); break;
-
- case scrollwindowtoken:
- scrollwindowverb (); break;
-
- case perftesttoken:
- perftestverb (); break;
-
- case alertdialogtoken:
- alertdialogverb (); break;
-
- case askdialogtoken:
- askdialogverb (); break;
-
- case confirmdialogtoken:
- confirmdialogverb (); break;
-
- case settargettoken:
- settargetverb (); break;
-
- case madechangestoken:
- madechangesverb (); break;
-
- case enabledialogtoken:
- enablealertverb (); break;
-
- case geterrorstringtoken:
- geterrorstringverb (); break;
-
- case nthwindowtoken:
- nthwindowverb (); break;
-
- case getfilepathtoken:
- getfilepathverb (); break;
-
- case movewindowtoken:
- movewindowverb (); break;
-
- case printwindowtoken:
- printwindowverb (); break;
-
- case getpagerecttoken:
- getpagerectverb (); break;
-
- case quittoken:
- quitverb (); break;
-
- case getwindowpostoken:
- getwindowposverb (); break;
-
- case countwindowstoken:
- countwindowsverb (); break;
-
- case getpicttoken:
- getpictverb (); break;
-
- case gettexttoken:
- gettextverb (); break;
-
- case putpicttoken:
- putpictverb (); break;
-
- case puttexttoken:
- puttextverb (); break;
-
- case selectalltoken:
- selectallverb (); break;
-
- case haveselectiontoken:
- haveselectionverb (); break;
-
- case getwindowrecttoken:
- getwindowrectverb (); break;
-
- case setfonttoken:
- setfontverb (); break;
-
- case setfontsizetoken:
- setfontsizeverb (); break;
-
- case getbinarytoken:
- getbinaryverb (); break;
-
- case putbinarytoken:
- putbinaryverb (); break;
-
- default:
- IACnothandlederror (); break;
- } /*switch*/
-
- return (noErr);
- } /*handleapp1verb*/
-
-
- static pascal Boolean openfilespec (fs) FSSpec *fs; {
-
- bigstring bs;
-
- if (!directorytopath ((*fs).parID, (*fs).vRefNum, bs))
- return (false);
-
- pushstring ((*fs).name, bs);
-
- if ((*app.opendoccallback) (bs)) /*the application handled the opendoc event*/
- return (true);
-
- if (!openwindow (bs, 0)) {
-
- IACreturnerror (-1, bserrorstring);
-
- return (false);
- }
-
- return (true);
- } /*openfilespec*/
-
-
- static pascal OSErr handleopen (AppleEvent *event, AppleEvent *reply, long refcon) {
-
- IACglobals.event = event;
-
- IACglobals.reply = reply;
-
- IACglobals.refcon = refcon;
-
- return (IACdrivefilelist (&openfilespec));
- } /*handleopen*/
-
-
- static pascal Boolean printfilespec (fs) FSSpec *fs; {
-
- hdlappwindow appwindow;
- bigstring fullpath;
- bigstring fname;
- short vnum;
-
- if (!directorytopath ((*fs).parID, (*fs).vRefNum, fullpath))
- return (false);
-
- pushstring ((*fs).name, fullpath);
-
- if (!pathtofileinfo (fullpath, fname, &vnum))
- return (false);
-
- if (findbyfile (fname, vnum, &appwindow))
- selectappwindow (appwindow);
-
- else {
- if (!openwindow (fullpath, 0)) {
-
- IACreturnerror (-1, bserrorstring);
-
- return (false);
- }
- }
-
- setfrontglobals (); /*event applies to frontmost window*/
-
- return (printappwindow (app.appwindow, false));
- } /*printfilespec*/
-
-
- static pascal OSErr handleprint (event, reply, refcon) AEDescList *event, *reply; long refcon; {
-
- IACglobals.event = event;
-
- IACglobals.reply = reply;
-
- IACglobals.refcon = refcon;
-
- return (IACdrivefilelist (&printfilespec));
- } /*handleprint*/
-
-
- static pascal OSErr handlequit (event, reply, refcon) AEDescList *event, *reply; long refcon; {
-
- exitmainloop ();
-
- return (noErr);
- } /*handlequit*/
-
-
- static pascal OSErr handleopenapp (event, reply, refcon) AEDescList *event, *reply; long refcon; {
-
- return (noErr);
- } /*handleopenapp*/
-
-
- pascal Boolean appscriptcomplete (void) {
-
- bigstring bs;
-
- resetdirtyscrollbars ();
-
- if (IACgetstringparam ('errs', bs)) {
-
- bigstring bsalert;
-
- copystring ("\pError in shared script. ", bsalert);
-
- pushstring (bs, bsalert);
-
- alertdialog (bsalert);
- }
-
- return (true);
- } /*appscriptcomplete*/
-
-
- static long casereverser (long id) {
-
- /*
- used in setting up the system event handler for the "fast" verbs that the applet
- implements. we reverse the case of each of the alpha characters in the id. for
- example, 'DOCS' turns into 'docs'. And 'ƒMnU' turns into 'ƒmNu'. originally we
- had each applet declare its system handler in the class 'fast', but this wouldn't
- work if more than one applet was running at a time.
- */
-
- char *p = (char *) &id;
- short i;
-
- for (i = 1; i <= 4; i++) {
-
- char ch = *p;
-
- if ((ch >= 'a') && (ch <= 'z'))
- ch -= 32;
- else
- if ((ch >= 'A') && (ch <= 'Z'))
- ch += 32;
-
- *p++ = ch;
- } /*for*/
-
- return (id);
- } /*casereverser*/
-
-
- static boolean initIAC (void) {
-
- setstringlength (bstargetwindowname, 0); /*no target window initially*/
-
- if (!InitSharedMenus ()) /*initialize the menusharing routines*/
- return (false);
-
- MSglobals.scriptcompletedcallback = (tyMScallback) &appscriptcomplete;
-
- if (!IACinstallhandler (app1class, typeWildCard, (ProcPtr) &handleapp1verb))
- return (false);
-
- if (!IACinstallhandler (app.creator, typeWildCard, (ProcPtr) &handlecustomverb))
- return (false);
-
- if (!IACinstallsystemhandler (casereverser (app.creator), typeWildCard, (ProcPtr) &handlefastverb))
- return (false);
-
- if (!IACinstallhandler (kCoreEventClass, kAEOpenApplication, (ProcPtr) &handleopenapp))
- return (false);
-
- if (!IACinstallhandler (kCoreEventClass, kAEOpenDocuments, (ProcPtr) &handleopen))
- return (false);
-
- if (!IACinstallhandler (kCoreEventClass, kAEPrintDocuments, (ProcPtr) &handleprint))
- return (false);
-
- if (!IACinstallhandler (kCoreEventClass, kAEQuitApplication, (ProcPtr) &handlequit))
- return (false);
-
- IACglobals.waitroutine = appwaitroutine;
-
- return (true);
- } /*initIAC*/
-
-
- static void initscrap (void) {
-
- PScrapStuff x;
-
- x = InfoScrap ();
-
- if ((*x).scrapState < 0) /*following advice of THINK Reference*/
- ZeroScrap ();
- } /*initscrap*/
-
-
- static boolean noopcallback (void) {
-
- /*sysbeep;*/
-
- return (false);
- } /*noopcallback*/
-
-
- static void checkcallback (tyappcallback *cb) {
-
- if (*cb == nil) /*the applet doesn't define this callback*/
- *cb = &noopcallback;
- } /*checkcallback*/
-
-
- static void normaleraserectcallback (Rect r) {
-
- EraseRect (&r);
- } /*normaleraserectcallback*/
-
-
- static boolean normalsetfontcallback (void) {
-
- hdlappwindow ha = app.appwindow;
- tyselectioninfo x = (**ha).selectioninfo;
-
- if (x.fontnum != -1)
- (**ha).defaultfont = x.fontnum;
-
- if (x.fontsize != -1)
- (**ha).defaultsize = x.fontsize;
-
- invalappwindow (ha, true);
-
- return (true);
- } /*normalsetfontcallback*/
-
-
- static void checknilcallbacks (void) {
-
- installscroll (); /*install the default handler if appropriate*/
-
- checkcallback (&app.newrecordcallback);
-
- checkcallback (&app.disposerecordcallback);
-
- checkcallback (&app.idlecallback);
-
- checkcallback ((tyappcallback *) &app.activatecallback);
-
- checkcallback (&app.updatecallback);
-
- checkcallback (&app.preupdatecallback);
-
- checkcallback (&app.windowresizecallback);
-
- checkcallback (&app.iacmessagecallback);
-
- checkcallback (&app.iacfastmessagecallback);
-
- checkcallback ((tyappcallback *) &app.packcallback);
-
- checkcallback ((tyappcallback *) &app.unpackcallback);
-
- checkcallback ((tyappcallback *) &app.gettextcallback);
-
- checkcallback ((tyappcallback *) &app.getpictcallback);
-
- checkcallback ((tyappcallback *) &app.scrollcallback);
-
- checkcallback (&app.scrolltocallback);
-
- checkcallback (&app.pagesetupcallback);
-
- checkcallback (&app.openprintcallback);
-
- checkcallback ((tyappcallback *) &app.printpagecallback);
-
- checkcallback (&app.closeprintcallback);
-
- checkcallback ((tyappcallback *) &app.puttextcallback);
-
- checkcallback ((tyappcallback *) &app.putpictcallback);
-
- checkcallback (&app.haveselectioncallback);
-
- checkcallback (&app.selectallcallback);
-
- checkcallback (&app.keystrokecallback);
-
- checkcallback (&app.mousecallback);
-
- checkcallback (&app.mouseinstatuscallback);
-
- checkcallback (&app.updatestatuscallback);
-
- checkcallback ((tyappcallback *) &app.menucallback);
-
- checkcallback (&app.insertmenucallback);
-
- checkcallback (&app.setselectioninfocallback);
-
- if (app.setfontcallback == nil)
- app.setfontcallback = &normalsetfontcallback;
-
- if (app.setsizecallback == nil)
- app.setsizecallback = &normalsetfontcallback;
-
- checkcallback (&app.setstylecallback);
-
- checkcallback (&app.setjustifycallback);
-
- checkcallback ((tyappcallback *) &app.copycallback);
-
- checkcallback (&app.clearcallback);
-
- checkcallback ((tyappcallback *) &app.pastecallback);
-
- checkcallback (&app.initmacintoshcallback);
-
- checkcallback ((tyappcallback *) &app.resumecallback);
-
- checkcallback ((tyappcallback *) &app.opendoccallback);
-
- if (app.eraserectcallback == nil)
- app.eraserectcallback = &normaleraserectcallback;
-
- checkcallback ((tyappcallback *) &app.getcontentsizecallback);
-
- checkcallback ((tyappcallback *) &app.setglobalscallback);
-
- checkcallback ((tyappcallback *) &app.getoptionscallback);
-
- checkcallback ((tyappcallback *) &app.putoptionscallback);
- } /*checknilcallbacks*/
-
-
- static boolean managersinited = false;
-
-
- void appletinitmanagers (void) {
-
- initmacintosh ();
-
- checknilcallbacks (); /*initmenus uses a callback routine*/
-
- initIAC ();
-
- appletheapzone = GetZone ();
-
- initmenus ();
-
- initscrap ();
-
- clearbytes (&mousestatus, longsizeof (mousestatus));
-
- (*app.initmacintoshcallback) ();
-
- managersinited = true;
- } /*appletinitmanagers*/
-
-
- void runapplet (void) {
-
- if (!managersinited)
- appletinitmanagers ();
-
- maineventloop ();
-
- IACremovesystemhandlers ();
- } /*runapplet*/
-